_realname=watchexec
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.22.3
pkgrel=2
url="https://watchexec.github.io/"
pkgdesc="Executes commands in response to file modifications (mingw-w64)"
license=('spdx:Apache-2.0')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("https://github.com/watchexec/watchexec/archive/v${pkgver}.tar.gz")
sha256sums=('698ed1dc178279594542f325b23f321c888c9c12c1960fe11c0ca48ba6edad76')

prepare() {
  cd "${_realname}-${pkgver}"

  # update windows-targets to fix windows-gnullvm dependency specification
  cargo update -p windows-targets@0.48.0 --precise 0.48.1
  cargo fetch --locked
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --frozen \
    --offline \
    --no-track \
    --path crates/cli \
    --root "${pkgdir}${MINGW_PREFIX}" \
    watchexec-cli

  install -Dm644 completions/zsh "$pkgdir${MINGW_PREFIX}/share/zsh/site-functions/_watchexec"
  install -Dm644 doc/watchexec.1 "$pkgdir${MINGW_PREFIX}/share/man/man1/watchexec.1"
  install -Dm644 doc/watchexec.1.pdf "$pkgdir${MINGW_PREFIX}/share/doc/watchexec/watchexec.1.pdf"
  install -Dm644 doc/watchexec.1.md "$pkgdir${MINGW_PREFIX}/share/doc/watchexec/watchexec.1.md"
  install -Dm644 doc/logo.svg "$pkgdir${MINGW_PREFIX}/share/icons/hicolor/scalable/apps/watchexec.svg"
  install -Dm644 LICENSE "$pkgdir${MINGW_PREFIX}/share/licenses/watchexec/LICENSE"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/watchexec/README"
}
